﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WSS.hameduconn.Business;
using WSS.hameduconn.Business.Dto;

namespace WSS.hameduconn.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult CheckedLogin(string username , string password)
        {
            CheckedLoginDto checkedLogin = CheckedLoginBusiness.CheckedLogin(username, password);
            ViewBag.UserId = checkedLogin.UserId;
            ViewBag.Permission = checkedLogin.Permission;
            return Json(checkedLogin, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult IsExistsUsername(string username)
        {
            CheckedLoginDto checkedLogin = CheckedLoginBusiness.CheckedUsername(username);            
            return Json(checkedLogin, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult RegistrationForUser(RegistrationsDto registration)
        {
            RegistrantionBusines.Inserted(registration);
            return Json(true);
        }

        public ActionResult UserInfo(int id)
        {
            RegistrationsDto registration = RegistrantionBusines.GetRegistrationById(id);
            return View(registration);
        }

        public ActionResult UpdatedUser(RegistrationsDto registration)
        {
            RegistrantionBusines.Updated(registration);
            return RedirectToAction("UserInfo", new { id = registration.Id });
        }
	}
}